/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package wso.dao;

import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import wso.dto.WsoOrigin;
import wso.global.BaseDao;

/**
 *
 * @author Violet_Ink
 */
public class OriginDaoImpl extends BaseDao implements OriginDao {

    public void saveOrUpdateOrigin(WsoOrigin origin) {
        saveOrUpdate(origin);
    }

    public void deleteOrigin(String originid) {
        Session session = getSession();
        Query query = null;
        StringBuilder str = new StringBuilder();
        str.append("update WsoOrigin org set org.isdeleted = true where org.originid = :originid");
        query = session.createQuery(str.toString());
        query.setString("originid", originid);

        query.executeUpdate();
    }

    public WsoOrigin[] getAllOrigin() {
        Session session = getSession();
        Query query = null;
        StringBuilder str = new StringBuilder();
        str.append("from WsoOrigin org where org.isdeleted = false");
        query = session.createQuery(str.toString());
        List originList = query.list();
        WsoOrigin[] result = new WsoOrigin[originList.size()];
        originList.toArray(result);

        return result;
    }

    public WsoOrigin getOrigin(String originid) {
        Session session = getSession();
        Query query = null;
        StringBuilder str = new StringBuilder();

        str.append("from WsoOrigin org where org.originid = :originid and org.isdeleted = false");
        query = session.createQuery(str.toString());
        query.setString("originid", originid);

        return (WsoOrigin) query.uniqueResult();
    }
}
